from rest_framework import serializers
from .models import Template
import json


class TemplateSerializer(serializers.ModelSerializer):
    """
    模板序列化器
    """
    
    class Meta:
        model = Template
        fields = [
            'id', 'name', 'task_blocks_layout', 'description', 'created_at', 'updated_at'
        ]
        read_only_fields = ['created_at', 'updated_at']


class TemplateCreateUpdateSerializer(serializers.ModelSerializer):
    """
    模板创建和更新序列化器
    """
    
    class Meta:
        model = Template
        fields = ['id', 'name', 'task_blocks_layout', 'description']
        read_only_fields = ['id']


class TemplateListSerializer(serializers.ModelSerializer):
    """
    模板列表序列化器
    用于列表页面，只包含基本信息
    """
    
    class Meta:
        model = Template
        fields = ['id', 'name', 'task_blocks_layout', 'description', 'created_at', 'updated_at']